<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/config.php");
require_once(APP_PATH."/Lib/ORG/t.class.php");
require_once(APP_PATH."/Lib/ORG/Mycurl.class.php");

$GLOBALS['mycurl']=new Mycurl();
$url=urldecode($_REQUEST['seccodeImage']);
if($url==""){
    $url=urldecode($_REQUEST['url']);
}
$c=$GLOBALS['mycurl']->result("",$url);
$cs=0;
do {
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, $url);
    curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.120 Safari/537.36");
    curl_setopt($ch, CURLOPT_REFERER, $url);
    curl_setopt($ch, CURLOPT_COOKIE, $c->cookie);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, "false");
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, "2");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 0);
    curl_setopt($ch, CURLOPT_VERBOSE, 0);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array("Host:{$c->qhost}", "Sec-Fetch-Mode: no-cors", "Sec-Fetch-Site: same-origin", "Connection:  keep-alive", "Accept:  image/webp,image/apng,image/*,*/*;q=0.8", "Accept-Language:  en-US,en;q=0.9,zh-CN;q=0.8,zh;q=0.7"));
    curl_setopt($ch, CURLOPT_HEADER, 1);
    curl_setopt($ch, CURLOPT_TIMEOUT, 60);
    $result = curl_exec($ch);
    $c->result($result,$url);
    curl_close($ch);

    if($c->location!=""&&$cs++<2){
        $url=$c->location;
        continue;
    }else{
        break;
    }
}while(1);

file_put_contents($_SERVER['DOCUMENT_ROOT']."/yzm.jpg",$c->body);
$result=array();
$result['regCode']=0;
$result['regMsg']="生成了新验证码";
echo json_encode($result);
exit(0);
